﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace CommonHelpers
{
    public static class Formatter
    {
        public static string ToMoney(this int x) 
        {
            CultureInfo ci = new CultureInfo("en-US");
            return x.ToString("#,0 Đ", ci);
        }

        public static string ToMoney(this long x)
        {
            CultureInfo ci = new CultureInfo("en-US");
            return x.ToString("#,0 Đ", ci);
        }

        public static int ToNumberFromMoney(this string x)
        {
            x = x.Replace(",", "");
            x = x.Replace("Đ", "");
            x = x.Trim();
            int result = 0;
            int temp;
            if (int.TryParse(x, out temp))
            {
                result = temp;
            }
            return result;
        }

        public static int ToNumber(this string x)
        {
            int result = 0;
            int temp;
            x = x.Trim();
            if (int.TryParse(x, out temp))
            {
                result = temp;
            }
            return result;
        }

        public static string ToDecimalString(this decimal x)
        {
            x = Math.Round(x, 2);
            return x.ToString(CultureInfo.InvariantCulture);
        }
    }
}
